package com.forekonw.demo8;


public class Master {
    public void cure(Pet pet) {
        if (pet.getHealth() < 60) {
           pet.toHospital();
        }
    }

    public void feed(Pet pet){
        pet.eat();
    }

    public void paly(Pet pet){
        if (pet instanceof Dog){
            Dog dog = (Dog) pet;//一定要有继承关系才能转换,如果需要调用子类型的新方法,需要强制类型转化
            dog.game();
        }else if (pet instanceof Penguin){
            Penguin p = (Penguin) pet;
            p.swimming();
        }
    }

    public static void main(String[] args) {
        Master master = new Master();
        Penguin p = new Penguin();
        master.paly(p);
        Dog d = new Dog();
        master.paly(d);
    }
}
